package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.view.View;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.CartoonMediaBean;
import com.fancy.learncenter.common.JumpIntentKey;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;
import com.fancy.learncenter.ui.callback.AlbumImpl;

import java.util.List;

/**
 * Created by shiweiwei on 2017/12/23.
 */

public class CartoonQuestionImageAdapter extends CommonRecycleViewAdapter<CartoonMediaBean>{


    public void setListener(AlbumImpl listener) {
        this.listener = listener;
    }

    AlbumImpl listener;
    JumpIntentKey.QUESTION_ENTER_TYPE type;

    public CartoonQuestionImageAdapter(Context mContext, JumpIntentKey.QUESTION_ENTER_TYPE type, List<CartoonMediaBean> itemDatas) {
        super(mContext, R.layout.cartoon_question_image_item, itemDatas);
        this.type = type;
    }




    @Override
    public void bindView(final CustomViewHold customViewHold, CartoonMediaBean item, final int position) {

        final SimpleDraweeView simpleDraweeView = customViewHold.getView(R.id.simpleDraweeView);
        simpleDraweeView.setImageURI(item.getImgUrl());
        final View framLayout = customViewHold.getView(R.id.frame_layout);

        switch (type){
            case DO_IT_AGAIN:
            case DO_WORK:
            case CONTINUE_WORK:
            case ERROR_KINDS:
                customViewHold.getRoorView().setEnabled(true);
                break;
            case WORK_REPORT:
                customViewHold.getRoorView().setEnabled(false);
                break;
            case NO_CLICK:
                customViewHold.getRoorView().setEnabled(false);
                break;
        }

        if (item.getStatus() == null){
            item.setStatus(JumpIntentKey.OPTION_STATUS.STATUS_DEFAULT);
        }


        switch (item.getStatus()){
            case STATUS_DEFAULT: //默认状态
                 framLayout.setVisibility(View.GONE);
                break;
            case STATUS_CHOOSE: //选中状态
                framLayout.setVisibility(View.VISIBLE);
                framLayout.setBackgroundResource(R.mipmap.cartoon_image_choose);
                break;
            case STATUS_RIGHT: //正确
                framLayout.setVisibility(View.VISIBLE);
                framLayout.setBackgroundResource(R.mipmap.cartoon_image_right);
                break;
            case STATUS_WRONG: //错误
                framLayout.setVisibility(View.VISIBLE);
                framLayout.setBackgroundResource(R.mipmap.cartoon_image_wrong);
                break;
        }

        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (listener != null){
                    listener.onClick(position);
                }
            }
        });


    }
}
